package net.yuxianghe;

import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

/**
 * Sender
 * Created by hxy on 16/12/26.
 */
public class Sender {

    public static void main(String[] args) {
        int port = 19099;
        String address = "224.0.1.199";
        String data = "hxy";
        for ( int i=100;i>0;i--){
            try {
                System.out.println(i);
                InetAddress inetAddress = InetAddress.getByName(address);
                DatagramPacket datagramPacket = new DatagramPacket(data.getBytes(), data.length(), inetAddress, port);
                MulticastSocket multicastSocket = new MulticastSocket();
                multicastSocket.setTimeToLive(254);
                multicastSocket.send(datagramPacket);
                multicastSocket.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
}
